package com.nf.health.app.intervention_details.fragment;


import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.google.gson.Gson;
import com.nf.health.app.Constants;
import com.nf.health.app.R;
import com.nf.health.app.fragment.IBaseFragment;
import com.nf.health.app.http.Act;
import com.nf.health.app.intervention_details.adapter.FoodDetailsAdapter;
import com.nf.health.app.intervention_details.bean.FoodDetailsBean;
import com.nf.health.app.utils.ViewUtil;

/**
 * 膳食方案
 *
 * @author changpeng 16/11/10
 */
public class FoodDetailsFragment extends IBaseFragment {
    private RecyclerView mRecyclerView;
    private FoodDetailsAdapter mFoodDetailsAdapter;
    private FoodDetailsBean mFoodDetailsBean;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        addViewFillInRoot(R.layout.common_layout_recycler);

        mRecyclerView = ViewUtil.getView(rootView, R.id.recycler_view_common);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        initData();
    }

    private void initData(){
        provider.getInterveneMedicineddiet(Constants.CHANGE_ABLE.INTERVENTION_ID);
    }

    @Override
    public void handleActionSuccess(String actionName, Object object) {
        if(actionName.equals(Act.Flag.GET_INTERVENE_MEDICINEDDIET)){
            Gson gson = new Gson();
            mFoodDetailsBean = gson.fromJson(object+"",FoodDetailsBean.class);
            if(mFoodDetailsBean == null){
                return;
            }
            mFoodDetailsAdapter = new FoodDetailsAdapter(getActivity(),mFoodDetailsBean);
            mRecyclerView.setAdapter(mFoodDetailsAdapter);
        }
    }
}
